package cn.bob.basic.listener;

import cn.bob.system.service.IPermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * @author bob
 * @data 2022/10/24-23:28
 */
//声明监听器
@WebListener
@Slf4j
public class PermissionScanlnlistener implements ServletContextListener {
    @Autowired
    private  IPermissionService iPermissionService;
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                log.info("contextInitialized start...");
                // 执行permission数据添加方法
                iPermissionService.scanPermission();
                log.info("contextInitialized stop...");
            }
        }).start();
    } // 程序停止时被调用

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        // 主动打印日志
        log.info("PermissionScanInitInstener stop..");
    }
}
